package com.wzj.uarmor.controller;


import com.wzj.uarmor.conf.SystemConfig;
import com.wzj.uarmor.entiy.SystemInfo;
import com.wzj.uarmor.utils.ResponseVO;
import com.wzj.uarmor.utils.ResultUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

/**
 * 系统信息
 *
 * @author whong
 * @date 2023/03/18
 */
@RestController
@RequestMapping("/sys")
@RequiredArgsConstructor
public class SystemController {

    private final SystemConfig systemConfig;

    @GetMapping("/getSystemInfos")
    public ResponseVO  getSystemInfos(){
        //调用 linux 服务
        SystemInfo systemInfo = new SystemInfo();
        Properties props=System.getProperties();
        systemInfo.setSystemName(props.getProperty("os.name"));
        systemInfo.setSystemType(props.getProperty("os.name"));
        systemInfo.setCpu(systemInfo.getCpu());
        systemInfo.setMemory(systemInfo.getMemory());
//        systemInfo.setUsedSize("15GB");
//        systemInfo.setTotalPhysicalMemory("500GB");
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        long uptime = runtimeMXBean.getUptime();
        long day = TimeUnit.MILLISECONDS.toDays(uptime);
        long hours = TimeUnit.MILLISECONDS.toHours(uptime);
        long minutes = TimeUnit.MILLISECONDS.toMinutes(uptime);
        /*long seconds = TimeUnit.MILLISECONDS.toSeconds(uptime);
        long ms = TimeUnit.MILLISECONDS.toMillis(uptime);*/
        systemInfo.setRunTime(String.format("%d天 %d时 %d分",day,hours,minutes));
        systemInfo.setSoftwareVersion(systemConfig.getSoftwareVersion());
        return ResultUtil.vo(systemInfo);
    }

}



